// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Parser front-end class

#ifndef FE_PARSERCONTEXT_H
#define FE_PARSERCONTEXT_H

#include <cstdio>
class ASTNode;
class Lexer2;
class Reader;

/**
 *
 * This class is an object-oriented front-end to the bison-generated
 * parser.
 */
class Parser {
private:
	Lexer2 *m_scanner;
	ASTNode *m_ast;

public:
	/** Constructor. */
	Parser();

	/** Destructor. */
	~Parser();

	/**
	 * Initialize the parser.
	 *
	 * @param readerToAdopt the Reader containing the source text to parse;
	 *                      will be automatically destroyed when the Parser is destroyed
	 */
	void initialize(Reader *readerToAdopt);

	/**
	 * Parse source text.
	 * Throws exception if any errors occur.
	 */
	void parse();

	/**
	 * Get abstract syntax tree constructed from source text.
	 *
	 * @return the ASTNode of the root of the abstract syntax tree
	 */
	ASTNode *getAST();

	/**
	 * Set the AST root.
	 * This should only be called by the generated bison parser.
	 */
	void setAST(ASTNode *ast);

	/**
	 * Get the scanner (Lexer2) being used to tokenize the source text.
	 */
	Lexer2 *getScanner();
};

#endif // FE_PARSERCONTEXT_H
